/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bagtest;

import java.util.ArrayList;

/**
 *
 * @author haoliang.donghl
 */
public abstract class AbstractAlgorithm {
    protected float capacity;
    protected ArrayList<Item> items;
    protected ArrayList<Item> inBag;
    protected float result = -1;


    public void setData(float capacity, ArrayList<Item> items, ArrayList<Item> inBag){
        this.capacity = capacity;
        this.items = items;
        this.inBag = inBag;
        result = -1;
    }

    public float getValue(){
        if (result >= 0) return result;
        float value;
        value = 0;
        for (Item item: inBag){
            value += item.getValue();
        }
        result = value;
        return value;
    }

    public void printResult(){
        System.out.print(getName() + ":\t");
        System.out.println(getValue());
    }

    public abstract String getName();
    public abstract void doCalculate();
    
}
